﻿using UnityEngine;
using System.Collections;

public class SquareEnemy : MonoBehaviour {
	public Color[] shapeColor;
	public int numberOfClicks = 2;
	public double respawnWaitTime = 2.0;
	public Transform explosion;
	public int enemyPoint = 2;
	
	private int storeClicks = 0;
	
	// Use this for initialization
	protected void Start () {
		storeClicks = numberOfClicks;
		Vector3 startPosition = new Vector3 (Random.Range (-6, 6), Random.Range (-4, 4), 0);
		transform.position = startPosition;
	}
	
	// Update is called once per frame
	protected void Update () {
		if (numberOfClicks <= 0) {
			if (explosion) {
				Instantiate(explosion, transform.position, transform.rotation);
			}
			Vector3 position = new Vector3 (Random.Range (-6, 6), Random.Range (-4, 4), 0);
			RespawnWaitTime();
			transform.position = position;
			numberOfClicks = storeClicks;
		}
	}
	
	protected void RespawnWaitTime() {
		renderer.enabled = false;
		RandomColor();
		//yield return new WaitForSeconds(respawnWaitTime);
		renderer.enabled = true;
	}
	
	protected void RandomColor () {
		if (shapeColor.Length > 0) {
			int newColor = Random.Range(0, shapeColor.Length);
			renderer.material.color = shapeColor[newColor];
		}
	}
}
